﻿#if WINDOWS_UWP || NETFX_CORE
#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2010-12-09 21:03:34Z</CreationDate>
</File>
*/
#endregion

using System;
using System.IO;
using System.Threading.Tasks;

using Windows.Foundation;
using Windows.Media.Capture;
using Windows.Storage;

namespace Outcoder.LauncherModel.Launchers
{
	/* TODO: [DV] Comment. */
	public class PhotoChooserLauncher : LauncherBase<PhotoResultBase>, IPhotoChooserLauncher
	{
		//TaskCompletionSource<PhotoResultBase> taskCompletionSource;
		//bool eventAdded;

        public override async Task<PhotoResultBase> ShowAsync()
        {
			CameraCaptureUI dialog = new CameraCaptureUI();

	        if (PixelHeight > 0 || PixelWidth > 0)
	        {
		        dialog.PhotoSettings.CroppedSizeInPixels = new Size(PixelWidth, PixelHeight);
	        }
			StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
			//			taskCompletionSource = new TaskCompletionSource<PhotoResultBase>();
			//
			//	        if (!eventAdded)
			//	        {
			//		        
			//	        }
			//
			//			return taskCompletionSource.Task;

	        if (file != null)
	        {
		        var result = new PhotoResult()
			        {
				        ChosenPhoto = await file.OpenStreamForReadAsync(),
						OriginalFileName = file.Name
			        };

		        return result;
	        }

	        return null;
        }

		public int PixelHeight { get; set; }

		public int PixelWidth { get; set; }

		public bool ShowCamera { get; set; }
	}

	public class PhotoResult : PhotoResultBase
	{
		
	}
}
#endif